package dynamic.mybatisplus.core;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import dynamic.DynamicEntity;
import dynamic.metadata.EntityClass;
import dynamic.mybatisplus.core.conditions.query.DLambdaQueryWrapper;
import dynamic.mybatisplus.core.conditions.query.DQueryWrapper;
import dynamic.mybatisplus.core.conditions.update.DLambdaUpdateWrapper;

import java.util.Collections;
import java.util.Map;

public final class DWrappers {
    /**
     * 空的 EmptyWrapper
     */
    private static final DQueryWrapper emptyWrapper = new EmptyWrapper();

 

    /**
     * 获取 QueryWrapper&lt;T&gt;
     *
     * @return QueryWrapper&lt;T&gt;
     */
    public static  DQueryWrapper query(EntityClass entityClass) {
        return new DQueryWrapper(entityClass);
    }

    /**
     * 获取 QueryWrapper&lt;T&gt;
     *
     * @param entity 实体类
     * 
     * @return QueryWrapper&lt;T&gt;
     */
    public static  DQueryWrapper query(DynamicEntity entity) {
        return new DQueryWrapper(entity);
    }

    

    

    /**
     * 获取 LambdaQueryWrapper&lt;T&gt;
     *
     * @param entity 实体类
     
     * @return LambdaQueryWrapper&lt;T&gt;
     */
    public static  DLambdaQueryWrapper lambdaQuery(DynamicEntity entity) {
        return new DLambdaQueryWrapper(entity);
    }

    /**
     * 获取 LambdaQueryWrapper&lt;T&gt;
     *
     * @param entityClass 实体类class
    
     * @return LambdaQueryWrapper&lt;T&gt;
     * @since 3.3.1
     */
    public static  DLambdaQueryWrapper lambdaQuery(EntityClass entityClass) {
        return new DLambdaQueryWrapper(entityClass);
    }


    /**
     * 获取 UpdateWrapper&lt;T&gt;
     *
     * @param entity 实体类
    
     * @return UpdateWrapper&lt;T&gt;
     */
    public static  UpdateWrapper update(DynamicEntity entity) {
        return new UpdateWrapper<>(entity);
    }



    /**
     * 获取 LambdaUpdateWrapper&lt;T&gt;
     *
     * @param entity 实体类
    
     * @return LambdaUpdateWrapper&lt;T&gt;
     */
    public static  LambdaUpdateWrapper lambdaUpdate(DynamicEntity entity) {
        return new LambdaUpdateWrapper<>(entity);
    }

    /**
     * 获取 LambdaUpdateWrapper&lt;T&gt;
     *
     * @param entityClass 实体类class
     * @return LambdaUpdateWrapper&lt;T&gt;
     * @since 3.3.1
     */
    public static DLambdaUpdateWrapper lambdaUpdate(EntityClass entityClass) {
        return new DLambdaUpdateWrapper(entityClass);
    }

    /**
     * 获取 EmptyWrapper&lt;T&gt;
     *
     * @return EmptyWrapper&lt;T&gt;
     * @see EmptyWrapper
     */
    @SuppressWarnings("unchecked")
    public static DQueryWrapper emptyWrapper() {
        return  emptyWrapper;
    }

    /**
     * 一个空的QueryWrapper子类该类不包含任何条件
     *
     * @param
     * @see DQueryWrapper
     */
    private static class EmptyWrapper extends DQueryWrapper {

        private static final long serialVersionUID = -2515957613998092272L;

        @Override
        public DynamicEntity getEntity() {
            return null;
        }

        @Override
        public EmptyWrapper setEntity(DynamicEntity entity) {
            throw new UnsupportedOperationException();
        }

        @Override
        public DQueryWrapper setEntityClass(EntityClass entityClass) {
            throw new UnsupportedOperationException();
        }

        @Override
        public EntityClass getEntityClass() {
            return null;
        }

        @Override
        public String getSqlSelect() {
            return null;
        }

        @Override
        public MergeSegments getExpression() {
            return null;
        }

        @Override
        public boolean isEmptyOfWhere() {
            return true;
        }

        @Override
        public boolean isEmptyOfNormal() {
            return true;
        }

        @Override
        public boolean isNonEmptyOfEntity() {
            return !isEmptyOfEntity();
        }

        @Override
        public boolean isEmptyOfEntity() {
            return true;
        }

        @Override
        protected void initNeed() {
        }

        @Override
        public EmptyWrapper last(boolean condition, String lastSql) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getSqlSegment() {
            return null;
        }

        @Override
        public Map<String, Object> getParamNameValuePairs() {
            return Collections.emptyMap();
        }

        @Override
        protected String columnsToString(String... columns) {
            return null;
        }

        @Override
        protected String columnToString(String column) {
            return null;
        }

        @Override
        protected EmptyWrapper instance() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void clear() {
            throw new UnsupportedOperationException();
        }
    }
}
